
import 'package:flutter_app/class/MyApp6.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyApp7 extends StatelessWidget {
   const MyApp7({super.key});

    @override
    Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      title: 'Flutter 动态切换widget',
      theme: ThemeData(
        primarySwatch: Colors.blue
      ),
      home: const SampleAppPage(),
    );
  }
}


class SampleAppPage extends StatefulWidget {
    const SampleAppPage({super.key});

    @override
    State<SampleAppPage> createState() => _SampleAppPageState();
}


class _SampleAppPageState extends State<SampleAppPage> {
  bool toggle = true;

  void _toggle(){
    setState(() {
      toggle = !toggle;
    });
  }

  _getToggleChild(){
    if(toggle){
      return const Text('Toggle One');
    }
    else {
      return CupertinoButton(
        onPressed: (){},
        child: const Text('Toggle Two'),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: const Text('Sample App'),
        actions: [
          IconButton(icon: const Icon(Icons.arrow_right),
              onPressed: (){
                Navigator.push(
                    context, MaterialPageRoute(builder: (context) => MyApp6()));
              })
        ],
      ),
      body: Center(
        child: _getToggleChild(),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _toggle,
        tooltip: 'Update Text',
        child: const Icon(Icons.update),
      ),
    );
  }
}